<template>
  <section class="xm-nav border-bottom-1px" :class="wrapperClass">
    <div class="nav-left" :class="leftClass">
      <span class="back-icon" :class="{'s-visibility':nav.left.isShow}" @click="back"></span>
    </div>
    <div class="nav-middle" :class="[{'s-visibility':nav.middle.isShow}, middleClass]">{{nav.middle.content}}</div>
    <div class="nav-right" :class="[{'s-visibility':nav.right.isShow}, rightClass]">
      <slot name="right">
        <span class="right-content">{{nav.right.content}}</span>
      </slot>
    </div>
  </section>
</template>

<script type="text/ecmascript-6">
  /*
    nav配置信息
    such as:
    const nacConf = {
      left: {
        isShow: true,
        type: 'IMG'
      },
      middle: {
        isShow: true,
        type: 'TEXT',
        content: '周边热点'
      },
      right: {
        isShow: false,
        type: 'TEXT',
        content: '右边'
      }
    };
  */
  export default {
    props: {
      nav: {
        type: Object,
        default () {
          return {
            left: {
              isShow: true,
              type: 'IMG'
            },
            middle: {
              isShow: true,
              type: 'TEXT',
              content: '熊猫天下'
            },
            right: {
              isShow: false,
              type: 'TEXT',
              content: '右边'
            }
          };
        }
      },
      wrapperClass: {
        type: null
      },
      leftClass: {
        type: null
      },
      middleClass: {
        type: null
      },
      rightClass: {
        type: null
      }
    },
    methods: {
      back () {
        if (this.nav.left.isShow) {
          window.history.back();
        }
      }
    }
  };
</script>

<style lang="less" rel="stylesheet/less">
  @import '../../common/css/mixin.less';
  @img-url: '../../components/nav/imgs/';
  .xm-nav{
    display: flex;
    height: 40px;
    color: #191919;
    background-color: #fff;
    overflow: hidden;
    box-shadow: 0 0px 5px rgba(7, 17, 27, 0.1);
    .border-bottom-1px(rgba(7, 17, 27, 0.1));
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    .nav-left, .nav-right{
      flex: 1;
    }
    .nav-left, .nav-right, .nav-middle{
      font-size: 0;
      height: 100%;
      line-height: 40px;
      visibility: hidden;
    }
    .nav-left{
      .back-icon{
        width: 50px;
        height: 100%;
        font-size: 16px;
        display: inline-block;
        background-position: 15px center;
        background-repeat: no-repeat;
        background-size: 11px 21px;
        .bg-img('@{img-url}back_'; 'png');
      }
    }
    .nav-middle{
      font-size: 16px;
    }
    .nav-right{
      text-align: right;
      .right-content{
        font-size: 16px;
        padding-right: 15px;
      }
    }
  }
</style>
